{extend name="_container/add"}

{block name="content"}
<input type="hidden" name="id" value="{:input('id')}">
<div class="layui-form-item">
    <label class="layui-form-label required">标签名<span></span></label>
    <div class="layui-input-inline">
        <input type="text" placeholder="" name="comment" id="info_comment" class="layui-input "
               lay-verify="required" value="{$r?$r['comment']:''}" style="" autocomplete="off">
        <div class="description"></div>
    </div>
    <div class="layui-form-mid layui-word-aux"></div>
</div>




<div class="layui-form-item">
    <label class="layui-form-label required">类型</label>
    <div class="layui-input-inline">
        <?php
                $formtype_inc = [
                "input"=> "单行文本框(input)",
        "date"=> "日期(date)",
        "time"=> "时间(time)",
        "select"=> "下拉框(select)",
        "select_sql"=> "下拉框(select_sql)",
        "file"=> "文件(file)",
        "video"=> "视频(video)",
        "image"=> "图片(image)",
        "morepic"=> "多图上传(morepic)",
        "textarea"=> "多行文本框(textarea)",
        "editor"=> "编辑器(editor)",
        "radio"=> "单选框(radio)",
        "checkbox"=> "复选框(checkbox)",
        "morevalue"=> "多值字段(morevalue)",
        "selects"=> "多选下拉(selects)",
        "selects_sql"=> "多选下拉(selects_sql)",
        "password"=> "密码框(password)",
        "baidumap"=> "百度地图(map)",
        "ssq" => "省市区三级联动",
        "ss" => "省市二级联动",
        ];
        ?>

        <select name="type" class="select2" lay-ignore id="view_type" style="width: 100%">
            {foreach $formtype_inc as $k=>$v}
            <option value="{$k}" {$r.type == $k ? 'selected' : ''}>{$v}</option>
            {/foreach}
        </select>
    </div>
</div>

<div class="layui-form-item" >
    <label class="layui-form-label required">一行多个</label>
    <div class="layui-input-inline">
        <select name="inline" class="select2" lay-ignore id="inline" style="width: 100%">
            <option value="0" {$r.inline?'':'selected'}>否</option>
            <option value="1" {$r.inline?'selected':''}>是</option>
        </select>
    </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label ">默认值<span></span></label>
    <div class="layui-input-inline">
        <input type="text" placeholder="" name="default" id="default" class="layui-input "
               value="{$r?$r['default']:''}" style="" autocomplete="off">
        <div class="description"></div>
    </div>
    <div class="layui-form-mid layui-word-aux"></div>
</div>

    <div class="layui-form-item" >
        <label class="layui-form-label">date格式</label>
        <div class="layui-input-inline">
            <select name="date" class="select2" lay-ignore id="view_format_date" style="width: 100%">
                <?php
                $date_format = [
                    0 =>  ['yyyy-MM-dd','Y-m-d','date'],
                    1 =>  ['yyyy-MM','Y-m', 'month'],
                    2 =>  ['MM-dd','m-d', 'date'],
                    3 =>  ['yyyy', 'Y', 'year']
                ];
                ?>
                {foreach $date_format as $k=>$v}
                <option value="{$k}" {$r.date == $k ? 'selected' : ''}>{$v[0]}</option>
                {/foreach}
            </select>
        </div>
    </div>

    <div class="layui-form-item" >
        <label class="layui-form-label">time格式</label>
        <div class="layui-input-inline">
            <select name="time" class="select2" lay-ignore id="view_format_time" style="width: 100%">
                <?php
                $time_format = [
                    0 => ['yyyy-MM-dd HH:mm:ss', 'Y-m-d H:i:s', 'datetime'],
                    1 => ['yyyy-MM-dd HH:mm', 'Y-m-d H:i', 'datetime'],
                    2 => ['yyyy-MM-dd HH', 'Y-m-d H', 'datetime'],
                    3 => ['MM-dd HH:mm:ss', 'm-d H:i:s', 'datetime'],
                    4 => ['MM-dd HH:mm', 'm-d H:i', 'datetime'],
                    5 => ['MM-dd HH', 'm-d H', 'datetime'],
                    6 => ['HH:mm:ss', 'H:i:s', 'time'],
                    7 => ['HH:mm', 'H:i','time'],
                    8 => ['HH', 'H', 'time'],
                ];
                ?>
                {foreach $time_format as $k=>$v}
                <option value="{$k}" {$r.time == $k ? 'selected' : ''}>{$v[0]}</option>
                {/foreach}
            </select>
        </div>
    </div>



    <div class="layui-form-item" >
        <label  class="layui-form-label" >width</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="width" value="{$r.width}"  id="view_width">
        </div>
    </div>


    <div class="layui-form-item" >
        <label  class="layui-form-label" >height</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="height" value="{$r.height}"  id="view_height">
        </div>
    </div>


    <div class="layui-form-item" >
        <label  class="layui-form-label" >是否sql数据配置 </label>
        <div class="layui-input-inline">
            <select name="is_sql" id="is_sql">
                <option value="1"  {$r.is_sql==1?'selected':''}>是</option>
                <option value="0" {$r.is_sql==0?'selected':''}>否</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item" >
        <label  class="layui-form-label" >数据配置</label>
        <div class="layui-input-inline">
            <textarea type="text" class="layui-textarea" name="data_set" value="{$r.data_set}"  id="view_data_set">{$r.data_set}</textarea>
        </div>
    </div>


{/block}
{block name="js"}
<script>
    function save_form3(obj) {
        save_form2(obj);
        return false;
    }
</script>

<script>
    let pre = "{:env('database.prefix')}";
    $('#info_comment').blur(
        function (obj) {
            let word = obj.target.value;
            if (word) {
                $.get('/auto/util/getEnglish?word=' + word, (data) => {
                    let res = data.result;
                    $('#info_name').val(res)
                })
            }
        }
    )
</script>


<script>
    $('#field_type').change(
        () => {
            let type = $("#field_type").val();
            switch (type) {
                case 'varchar':
                    $('#field_length').val(255);
                    $('#field_default').val('');
                    break;
                case 'int':
                    $('#field_length').val(11);
                    $('#field_default').val('0');
                    break;
                case 'tinyint':
                    $('#field_length').val(1);
                    $('#field_default').val(0);
                    break;
                case 'double':
                    $('#field_length').val('10,2');
                    $('#field_default').val('0.00');
                    break;
                case 'text':
                    $('#field_length').val('');
                    $('#field_default').val('');
                    break;
                case 'longtext':
                    $('#field_length').val('');
                    $('#field_default').val('');
                    break;
                case 'char':
                    $('#field_length').val('32');
                    $('#field_default').val('');
                    break;
                case 'json':
                    $('#field_length').val('');
                    $('#field_default').val('');
                    break;
            }
        }
    )
</script>
{/block}

{/extend}
